<template>
  <div style="padding-top: 20px">
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="按日期查找">
        <el-date-picker v-model="ruleForm.start" type="date" placeholder="日期" style="width: 100%;" />
      </el-form-item>
      <el-form-item label="按内容查找">
        <el-input placeholder="请输入内容" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>

    <el-table
      :data="tableData"
      border
      style="width: 100%"
    >
      <el-table-column
        fixed
        prop="recruitId"
        label="计划书编号"
        width="150"
      />
      <el-table-column
        prop="status"
        label="审核状态"
        width="100"
        filter-placement="bottom-end"
      >
        <template slot-scope="scope">
          <el-tag
            disable-transitions
          >{{ scope.row.status }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="recruitName"
        label="计划书标题"
        width="120"
      />
      <el-table-column
        prop="applyDepatment"
        label="部门"
        width="120"
      />
      <el-table-column
        prop="recruitPeopleNum"
        label="招聘人数"
        width="120"
      />
      <el-table-column
        prop="releaseTime"
        label="发布日期"
        width="300"
      />
      <el-table-column
        prop="userName"
        label="发布人"
        width="120"
      />
      <el-table-column
        prop="recruitStart"
        label="开始日期"
        width="120"
      />
      <el-table-column
        prop="recruitEnd"
        label="结束日期"
        width="120"
      />
      <el-table-column
        prop="recruitRequirements"
        label="招聘要求"
        width="120"
      />
      <el-table-column
        fixed="right"
        label="操作"
        width="100"
      >
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="editRecruit(scope.row.recruitId)">审核</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="修改招聘计划书" :visible.sync="dialogTableVisible">
      <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
        <el-form-item label="发布人" prop="name">
          <el-input v-model="ruleForm.userName" disabled />
        </el-form-item>
        <el-form-item label="计划书标题" prop="name">
          <el-input v-model="ruleForm.title" />
        </el-form-item>
        <el-form-item label="招聘人数" required>
          <el-input-number v-model="ruleForm.num" controls-position="right" :min="1" :max="10" />
        </el-form-item>
        <el-form-item label="开始时间" required>
          <el-input v-model="ruleForm.start" />
        </el-form-item>
        <el-form-item label="结束时间" required>
          <el-input v-model="ruleForm.end" />
        </el-form-item>
        <el-form-item label="发布部门" required>
          <el-input v-model="ruleForm.department" disabled />
        </el-form-item>
        <el-form-item label="发布时间" required>
          <el-input v-model="ruleForm.releaseTime" disabled />
        </el-form-item>
        <el-form-item label="职位要求" prop="desc">
          <el-input v-model="ruleForm.requirements" type="textarea" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="checkOK">通过</el-button>
          <el-button type="danger" @click="checkNO">不通过</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

  </div>
</template>

<script>
import { getAllRecruit } from '../../api/Artisan'
import { getRecruitInfoById } from '../../api/Artisan'
import { checkOK } from '../../api/Artisan'
import { checkNO } from '../../api/Artisan'
export default {
  name: 'CheckPlan',
  data() {
    return {
      dialogTableVisible: false,
      edit: false,
      del: false,
      num: 1, // 招聘人数
      userId: '', // 技术人员账号
      recruitInfo: '',
      departmentList: [],
      page: 1,
      formInline: {
        user: '',
        region: ''
      },
      tableData: [],

      ruleForm: {
        recruitId: '',
        title: '',
        status: '',
        num: '',
        start: '',
        end: '',
        department: '',
        requirements: '',
        releaseTime: '',
        userName: ''
      }
    }
  },
  created() {
    this.listRecruit()
  },

  methods: {
    /**
             * 审核通过
             */
    checkOK() {
      checkOK(this.ruleForm).then(res => {
        this.$message('审核完成')
        this.listRecruit()
        this.dialogTableVisible = false
      }).catch(err => {
        this.$message.error('审核异常' + err)
      })
    },

    /**
             * 审核不通过
             */
    checkNO() {
      checkNO(this.ruleForm.recruitId).then(res => {
        this.$message('审核完成')
        this.listRecruit()
        this.dialogTableVisible = false
      }).catch(err => {
        this.$message.error('审核异常' + err)
      })
    },

    /**
             * 查询所有招聘计划书
             */
    listRecruit() {
      getAllRecruit(this.page).then(res => {
        this.tableData = res.data
      })
    },

    /**
             * 修改招聘计划书（弹出框）
             * @param recruitId
             */
    editRecruit(recruitId) {
      getRecruitInfoById(recruitId).then(res => {
        this.ruleForm.recruitId = res.data.recruitId
        this.ruleForm.title = res.data.recruitName
        this.ruleForm.status = res.data.status
        this.ruleForm.department = res.data.applyDepatment
        this.ruleForm.num = res.data.recruitPeopleNum
        this.ruleForm.releaseTime = res.data.releaseTime
        this.ruleForm.userName = res.data.userName
        this.ruleForm.start = res.data.recruitStart
        this.ruleForm.end = res.data.recruitEnd
        this.ruleForm.requirements = res.data.recruitRequirements
        this.dialogTableVisible = true
      }).catch(err => {
        this.$message.error('修改异常' + err)
      })
    }
  }

}
</script>

<style scoped>

</style>
